<?
if ($this->file->GetId())
    $title = 'Редактирование файла';
else
    $title = 'Добавление файла';   
?>
<h1><?=$title;?></h1>
<form action="<?=MozgRoute::Get('http')->Create(array('module' => 'admin', 'ctrl' => $this->ctrlName, 'action' => 'save_media'));?>"
	method="post" enctype="multipart/form-data">
<table align="center" class="formTable">
	<tr>
		<td class="field-title"><label>Файл</label></td>
		<td class="field-place">
<?
	if (!$this->file->GetId())
	{ 
?>
	<div>
		<input type="radio" name="select_file_input_type" id="select_file_input_type_d" value="d"<?php echo ($this->file->GetTempFile() || !$this->file->GetLocalUrlFile() ? 'checked="checked"' : '') ?>> <label for="select_file_input_type_d" style="display: inline;">Закачать</label>&nbsp;&nbsp;
		<input type="radio" name="select_file_input_type" id="select_file_input_type_s" value="s"<?php echo (!$this->file->GetTempFile() && $this->file->GetLocalUrlFile() ? 'checked="checked"' : '') ?>> <label for="select_file_input_type_s" style="display: inline;">Выбрать с сервера</label>
	</div>	
	<div id="media_file_input_container_d" class="input-media-file" style="display: none;"><input name="media_file" type="file"></div>
	<div id="media_file_input_container_s" class="input-media-file" style="display: none;"><input type="text" name="media_file_server" id="media_file_server" value="<?php echo $this->file->GetLocalUrlFile() ? htmlspecialchars($this->file->GetLocalUrlFile()) : ''; ?>" width="150" readonly>&nbsp;<input type="button" id="button_media_server" value="Выбрать" class="bt" />
		<script type="text/javascript">
			function SetFileField_MediaFileServer( fileUrl )
			{
			  $('#media_file_server').val(fileUrl);
			}
	
			$(document).ready(
			  function()
			  {

				$('input[name=select_file_input_type]').change(function(){
					if (!this.checked) return;
						
					$('.input-media-file').hide();
					$('#media_file_input_container_'+this.value).show();
				}).trigger('change');	
									  
				$("#button_media_server").click(
					function(e)
					{
						CKFinder.Popup('<?=_FILEMANAGER_URL;?>', 620, 450, SetFileField_MediaFileServer, 'Images');
					}
				);
			  }
			)
		</script>
	</div>
<?php 
	}
	else
	{
		echo $this->mediaHTML;	
	}
?>	
		</td>
	</tr>
	<tr>
		<td class="field-title"><label>Дата</label></td>
		<td class="field-place"><input name="publish_date" type="text" value="<?=htmlspecialchars($this->file->GetPublishDate());?>"></td>
	</tr>
	<tr>
		<td class="field-title"><label>Название</label></td>
		<td class="field-place"><input name="title" type="text" value="<?=htmlspecialchars($this->file->GetTitle());?>"></td>
	</tr>
	<tr>
		<td class="field-title"><label>Описание</label></td>
		<td class="field-place">
			<label for="mediaDescription" class="editor-init-button editorInitButton">редактор</label>
			<textarea name="description" id="mediaDescription" cols="35" rows="5"><?=htmlspecialchars($this->file->GetDescription());?></textarea>
		</td>
	</tr>
	<tr>
		<td class="field-title"><label>Тэги</label></td>
		<td class="field-place"><div id="tagSuggest" class="tagBox">
				<input name="tags" id="tags" class="tagBoxInput" type="text" value="<?=htmlspecialchars($this->file->GetTags());?>" style="width: 300px;">
			</div>
		</td>
	</tr>					
</table>
<table>
	<tr>
		<td class="r"><input type="submit" value="Сохранить" class="bt" /></td>
		<td class="l"><input type="button" value="Назад" class="bt"
			onClick="window.location.href='<?=MozgRoute::Get('http')->Create(array('module' => 'admin', 'ctrl' => $this->ctrlName));?>';" /></td>
	</tr>
</table>
<input type="hidden" name="id" value="<?=$this->file->GetId();?>">
</form>
<?=$this->Style()->IncludeStyleFile(array('js' => 'tagdragon'));?>
<?=$this->Style()->IncludeStyleFile(array('js' => 'ckfinder'));?>
<?=$this->Style()->IncludeStyleFile(array('js' => array('ckeditor')));?>
<script type="text/javascript">
$(document).ready(function() {
	$('#tagSuggest').tagdragon({'field':'tags',
								 'max':10,
								 'charMin':2,
								 'tagsep':',',
								 'url':'<?=MozgRoute::Get('http')->Create(array('module' => 'admin', 'ctrl' => 'articles', 'action' => 'tags_list', 'blog' => 0));?>'});
});
</script>